package com.zhanghaijun.web.filter;

import com.zhanghaijun.service.ZUserServiceImpl;
import com.zhanghaijun.util.PrintUtil;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.*;
import java.io.IOException;

/**
 * Created by zhanghaijun on 15/8/12.
 */
public class FilterTest implements Filter {


    private String testParam;


    /**
     * 拦截器初始化
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        PrintUtil.println("filter init");
        testParam = filterConfig.getInitParameter("test");
        PrintUtil.println(testParam);
    }

    /**
     * 过滤请求
     * @param request
     * @param response
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        PrintUtil.println("filter data");
        filterChain.doFilter(request,response);

    }

    /**
     * 拦截器销毁
     */
    @Override
    public void destroy() {
        PrintUtil.println("filter destroy");
        testParam = null;
    }

    @Autowired
    ZUserServiceImpl zUserService;
}
